<template>
  <div class="login-page">
    <div class="login-box">
      <div class="title">
         后台管理系统
      </div>
      <div class="user-login ">
        <div class="cFloat">
          <div class="fl enter">用户登录</div>
          <div class="error-hint fr">
            <img src="~@/assets/icon/danger.png" alt="">
            <span v-if="errorTitle">密码错误，请重新输入</span>
          </div>
        </div>
        <div class="login-input">
          <div class="username">
              <i></i>
              <input type="text"  v-model="userName" placeholder="输入用户名"/>
          </div>
           <div class="password">
              <i></i>
              <input type="password"  v-model="userPassWord" placeholder="输入用户密码"/>
          </div>
        </div>
        <div class="submit-btn" @click="subParams" @keyup.enter.native="subParams">登录</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      errorTitle: true,
      userName: '',
      userPassWord: ''
    }
  },
  mounted () {
    if (this.$route.path === '/login') {
      this.$store.commit('setToken', '')
    }
    var inputList = document.querySelectorAll(
      '.el-input input.el-input__inner'
    )
    inputList.forEach(function (val, index) {
      val.style.paddingLeft = '30px'
      val.style.height = '50px'
    })
  },
  methods: {
    openFullScreen () {
      this.fullscreenLoading = true
      setTimeout(() => {
        this.fullscreenLoading = false
      }, 3000)
    },
    getParams (attr, data) {
      this[attr] = data
    },
    errMsg (str) {
      this.$message({
        showClose: true,
        message: str,
        duration: 2000,
        type: 'warning'
      })
    },
    subParams () {
      if (this.userName === '') {
        this.errMsg('用户名不能为空')
        return false
      }
      if (this.userPassWord === '') {
        this.errMsg('密码不能为空')
        return false
      }

      // this.$http({
      //   method: 'POST',
      //   url: this.ip.yintong + 'admin/login',
      //   params: {
      //     email: this.userName,
      //     pswd: this.userPassWord
      //   }
      // }).then((res) => {
      //   if (res.body.code == 200) {
      //     // 登录的遮罩层
      //     this.openFullScreen()

      this.$store.commit('setToken', 'token1234')
      console.log(this)
      this.$router.push({ path: '/' })
      //   } else if (res.body.code == 400) {
      //     this.errMsg(res.body.msg)
      //   }
      // }), (err) => {
      //   console.log(err)
      // }
    }
  }
}
</script>

<style scoped lang='scss'>
.login-page {
  position: relative;
  width: 100%;
  height: 100vh;
  background: url("~@/assets/bg.png") no-repeat;
  margin: 0 auto;
  .login-box {
    width: 384px;
    height: 394px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0px 0px 30px rgba(30, 56, 116, 0.5);
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
    .title {
      width: 256px;
      height: 54px;
      line-height: 54px;
      font-size: 24px;
      font-family: MicrosoftYaHei;
      color: #ffffff;
      background: url("~@/assets/loginBg.png") no-repeat;
      margin: -14px auto 0;
      border-radius: 0 0 10px 10px;
    }
    .user-login {
      padding: 0 32px;
      margin-top: 55px;
      line-height: 18px;
      .error-hint {
        vertical-align: middle;
        img {
          display: inline-block;
          width: 18px;
          height: 18px;
        }
      }
      .login-input {
        margin: 30px 0 58px;
        .username,
        .password {
          height: 46px;
          border: 1px solid #e4e4e4;
          input {
            height: 44px;
            display: inline-block;
            width: 100%;
            padding-left: 40px;
          }
        }
        .username {
          position: relative;
          margin-bottom: 18px;
          i {
            position: absolute;
            top: 10px;
            left: 11px;
            width: 20px;
            height: 20px;
            background: url("~@/assets/icon/user.png");
            background-size: 100% 100%;
          }
        }
        .password {
          position: relative;
          margin-bottom: 18px;
          i {
            position: absolute;
            top: 10px;
            left: 11px;
            width: 20px;
            height: 20px;
            background: url("~@/assets/icon/password.png");
            background-size: 100% 100%;
          }
        }
      }
      .submit-btn {
        width: 316px;
        height: 44px;
        line-height: 44px;
        background: linear-gradient(to bottom,#29437F,#3C5898);
        border-radius: 22px;
        color: #ffffff;
        font-size: 18px;
      }
    }
  }
}
</style>
